<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>系统管理</el-breadcrumb-item>
                <el-breadcrumb-item>用户管理</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框杀杀杀
                 :model="双向绑定表单的数据"
            -->
            <el-form :inline="true" :model="carFormData"  class="demo-form-inline">
                <el-form-item >
                    <el-input v-model="carFormData.carName" placeholder="请输入汽车名字"></el-input>
                </el-form-item>
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.loginName" placeholder="请输入昵称"></el-input>-->
                <!--                </el-form-item>-->
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.email" placeholder="请输入邮箱"></el-input>-->
                <!--                </el-form-item>-->
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.phone" placeholder="请输入电话"></el-input>-->
                <!--                </el-form-item>-->
                <el-form-item>
                    <el-button type="primary" @click="chaxun">查询</el-button>
<!--                    <el-button type="primary" @click="insert">添加</el-button>-->
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="编号"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="tbCar.carName"
                            label="车名"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="tbClient.clientName"
                            label="评论客户">
                    </el-table-column>
                    <el-table-column
                            prop="useNum"
                            label="点赞数">
                    </el-table-column>
                    <el-table-column
                            prop="content"
                            label="评论内容">
                    </el-table-column>
                    <el-table-column
                            prop="addtime"
                            label="评论时间">
                    </el-table-column>


                    <el-table-column label="操作">
                        <template slot-scope="scope">
<!--                            <el-button type="primary" icon="el-icon-edit" circle @click="selectById(scope.row.id)"></el-button>-->
                            <el-button type="danger" icon="el-icon-delete" circle @click="deleteById(scope.row.id)"></el-button>
                            <!--                            <el-button type="warning" icon="el-icon-star-off" circle @click="showUserRole(scope.row.userId)"></el-button>-->
                        </template>
                    </el-table-column>
                </el-table>

                <!--                分页-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </template>
        </el-card>


        <el-dialog
                title="提示"
                :visible.sync="editDialogVisible"
                width="30%"
        >
            <!--            model:表单数据-->
            <el-form  label-width="80px" :model="carTypeForm" :rules="carTypeFormRules" ref="carTypeFormRef" >
                <el-form-item label="id" style="display: none">
                    <el-input v-model="carTypeForm.id" ></el-input>
                </el-form-item>
                <el-form-item label="用户id" prop="clientId">
                    <el-input v-model.number="carTypeForm.clientId"></el-input>
                </el-form-item>
                <el-form-item label="汽车id" prop="carId">
                    <el-input v-model.number="carTypeForm.carId"></el-input>
                </el-form-item>
                <el-form-item label="评论" prop="content">
                    <el-input v-model="carTypeForm.content"></el-input>
                </el-form-item>

                <el-form-item label="点赞数" prop="useNum">
                    <el-input v-model.number="carTypeForm.useNum"></el-input>
                </el-form-item>
                <el-form-item label="时间" >
                    <el-form-item >
                        <el-date-picker
                                v-model="carTypeForm.addtime"
                                type="date"
                                placeholder="日期">
                        </el-date-picker>
                    </el-form-item>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="formSubmit">确 定</el-button>
              </span>
        </el-dialog>

        <div id="asd" style="width: 600px;height:400px;"></div>

<!--        <div>-->
<!--        <el-steps  :active="active">-->
<!--            <el-step title="步骤 1" description="这是一段很长很长很长的描述性文字"></el-step>-->
<!--            <el-step title="步骤 2" description="这是一段很长很长很长的描述性文字"></el-step>-->
<!--            <el-step title="步骤 3" description="这段就没那么长了"></el-step>-->
<!--        </el-steps>-->
<!--          <div v-if="active==0">-->
<!--              <el-button @click="prevs" ></el-button>-->
<!--          </div>-->
<!--          <div v-if="active==1"></div>-->
<!--            <div v-if="active==1">-->

<!--                <el-input></el-input>-->
<!--                <el-input></el-input>-->
<!--                <el-input></el-input>-->
<!--                <el-input></el-input>-->
<!--                <el-button @click="prevs" ></el-button>-->

<!--            </div>-->
<!--            <div v-if="this.active==2">-->
<!--                <el-button @click="prevs" ></el-button>-->
<!--            </div>-->
<!--        </div>-->
    </div>





</template>

<script>
    export default {
        name: "CarComment",
        data(){
            return {
                active:0,
                editDialogVisible:false,
                //条件搜索对象
                carFormData:{},
                //表格数据
                tableData:[],
                //每页显示的条数
                pageSize: 5,
                //当前的显示的页码
                currentPage:1,
                //总条数
                total:0,

                carTypeForm:{},
                carTypeFormRules:{
                    clientId:[
                        { required:true,message:"不能为空",trigger:"blur"},
                        {type: 'number', message: '数量必须为数字值'}
                    ],
                    carId:[
                        { required:true,message:"不能为空",trigger:"blur"},
                        {type: 'number', message: '数量必须为数字值'}
                    ],
                    useNum:[
                        { required:true,message:"不能为空",trigger:"blur"},
                        {type: 'number', message: '数量必须为数字值'}
                    ],
                    content:[
                        { required:true,message:"不能为空",trigger:"blur"},
                    ]
                }


            }
        },
        created() {
            this.selectall();
            setTimeout( ()=>{ //延时加载echarts初始化函数
                this.myEcharts()
            },100)
        },
        methods:{
            myEcharts(){
                // 基于准备好的dom，初始化echarts实例
                var myChart = this.$echarts.init(document.getElementById('asd'));
                var that=this;
                  this.$http.get("rents/treeSelect").then(function (returnResult) {
                        var x=returnResult.data.result.treeSelect.x;
                        var y=returnResult.data.result.treeSelect.y;
                      var option = {
                          xAxis: {
                              type: 'category',
                              data: x
                          },
                          yAxis: {
                              type: 'value'
                          },
                          series: [{
                              data: y,
                              type: 'bar',
                              showBackground: true,
                              backgroundStyle: {
                                  color: 'rgba(180, 180, 180, 0.2)'
                              }
                          }]
                      };

                      // 使用刚指定的配置项和数据显示图表。
                      myChart.setOption(option);
                  })



            },
            prevs(){
               this.active=this.active+1;
            },
            selectall(){
                var that=this;
              this.$http.post(`/rents/comment/selectall/${this.currentPage}/${this.pageSize}`,this.carFormData).then(function (returnResult) {
                       that.tableData=returnResult.data.result.records;
                       that.total=returnResult.data.result.total;
              })
            },
            chaxun(){
              this.selectall();
            },
            insert(){
                this.editDialogVisible=true;
                this.carTypeForm={};
            },
            selectById(id){
                this.editDialogVisible=true;
                var that=this;
                  this.$http.get(`rents/comment/selectById/${id}`).then(function (returnResult) {

                           that.carTypeForm=returnResult.data.result.huixian;
                  })
            },
            deleteById(id){
                var that=this;
               this.$http.delete(`rents/comment?id=`+id).then(function (returnResult) {
                      alert("删除成功");
                      that.selectall();
               })
            },
            formSubmit(){
                this.$refs.carTypeFormRef.validate((valid)=>{
                    if(valid){
                        var that=this;
                        if(this.carTypeForm.id!=null){
                            this.$http.put("rents/comment/update",this.carTypeForm).then(function (returnResult) {
                                that.editDialogVisible=false;
                                that.carTypeForm={};
                                that.selectall();
                            })
                        }else {
                            this.$http.post("rents/comment/insert", this.carTypeForm).then(function (returnResult) {
                                that.editDialogVisible = false;
                                that.selectall();
                            })
                        }
                    }

                })

            },
            handleSizeChange(v){
                this.pageSize=v;
                this.selectall();            },
            handleCurrentChange(v){
                this.currentPage=v;
                this.selectall();
            }


        }
    }
</script>

<style scoped>

</style>